<?php
namespace app\index\model;

use think\Model;

class CapitalFlow extends Model
{
    //资金流水表
    protected $table = 'sn_capital_flow';
    //关联用户表
    public function user()
    {
        return $this->belongsTo('User', 'uid', 'id');
    }

    /** 资金流水
     * @param $map
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function query_list($map)
    {
        $list = $this->relation(array('user'))->where($map)->paginate();
        foreach ($list as $k=>$v)
        {
            $list[$k]['type'] = $this->type_name($v['type']);
        }
        return $list;
    }

    //资金流水状态
    public function type_name($type)
    {
        switch ($type) {
            case 1:
                $name = '增加';
                break;
            case 2:
                $name = '减少';
                break;
            default:
                $name = '';
                break;
        }
        return $name;
    }
}